﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<script>
    var keyValue = request('keyValue');
    var itemId = request('itemId');
    var parentId = request('parentId');
    var SystemFlag = false;
    $(function () {
        initControl();
    })
    //初始化控件
    function initControl() {
        //上级
        $("#ParentId").ComboBoxTree({
            url: "../../SystemManage/DataItemDetail/GetTreeJson",
            param: { parentId: parentId, itemid: itemId },
            description: "==请选择==",
            height: "230px"
        });

        //获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "../../SystemManage/DataItemDetail/GetForm",
                param: { keyValue: keyValue },
                success: function (data) {                    
                    if (data.IsSystem == 1) {
                        SystemFlag = true;
                        $("#ItemCode").attr('disabled', 'disabled');
                        $("#ItemValue").attr('disabled', 'disabled');                        
                    }                               
                    $("#form1").SetWebControls(data);                  
                    $("#ParentId").ComBoxSetValue(data.ParentId);                   
                }
            });
        } else {
            $("#ParentIdTree").val(parentId);
            $("#ItemId").val(itemId);
        }
    }
    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);        
        postData["ItemId"] = itemId;
        postData["ParentId"] = 0;
        postData["IsSystem"] = SystemFlag == true ? 1 : 0;
        postData["ItemCode"] = postData["ItemName"];
        $.SaveForm({
            url: "../../SystemManage/DataItemDetail/SaveForm?keyValue=" + keyValue,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").resetSelection();
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        })
    }
    //验证：项目值、项目名 不能重复
    function OverrideExistField(id, url) {
        $.ExistField(id, url, { itemId: itemId });
    }
</script>
<div style="margin-top: 20px; margin-right: 30px;">   
    <table class="form">       
        @*<tr>
        <th class="formTitle">上级</th>
        <td class="formValue">
            <div id="ParentId" type="selectTree" class="ui-select" isvalid="yes" checkexpession="IsScript"></div>
        </td>
    </tr>
    <tr>
        <td class="formTitle">词典编码<font face="宋体">*</font></td>
        <td class="formValue">
            <input id="ItemCode" type="text"  class="form-control" placeholder="请输入项目名" isvalid="yes" checkexpession="NotNull" />
        </td>
    </tr>*@
        <tr>
            <td class="formTitle">词典名称<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="ItemName" type="text" onblur="OverrideExistField(this.id,'../../SystemManage/DataItemDetail/ExistItemName')" class="form-control" placeholder="请输入词典名称" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">词典值</td>
            <td class="formValue">
                <input id="ItemValue" type="text" class="form-control" placeholder="请输入词典值" isvalid="yes" checkexpession="IsScript" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">排序<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="SortCode" type="text" class="form-control" isvalid="yes" checkexpession="Num" />
            </td>
        </tr>
        <tr>
            <th class="formTitle" style="height: 37px;"></th>
            <td class="formValue">
                <div class="checkbox">
                    <label>
                        <input id="EnabledMark" type="checkbox" checked="checked" />
                        有效
                    </label>
                </div>
            </td>
        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;">
                备注
            </th>
            <td class="formValue">
                <textarea id="Description" class="form-control" style="height: 70px;" isvalid="yes" checkexpession="IsScript"></textarea>
            </td>
        </tr>
    </table>
</div>

